import React,{ Component } from 'react';
import { withRouter } from 'react-router-dom';

@withRouter
export default class Fill extends Component{
  static defaultProps = {
    prefixCls: 'voting-container-fill'
  }

  constructor(props) {
    super(props);
    this.id = props.match.params && props.match.params.id;
    this.resourceid = props.location.search ? props.location.search.match(/sourceid=([\d]+)$/)[1] : null;
    window.top.openVotiongLink = this.openVotiongLink;
  }

  openVotiongLink = (href) => {
    window.openLink(href);
  }

  render() {
    const { prefixCls, type } = this.props;
    let viewUrl = this.resourceid ? 
      `/voting/mobile/index.jsp#&/voting/mobile/answerMy.jsp?id=${this.id}&resourceid=${this.resourceid}` :
      `/voting/mobile/index.jsp#&/voting/mobile/answerMy.jsp?id=${this.id}`;
    let iframUrl = type === 'view' ? viewUrl : 
       `/voting/mobile/index.jsp#&/voting/mobile/answer.jsp?id=${this.id}`
    return (
      <div className={prefixCls}>
        <iframe id='iframe' className={`${prefixCls}-iframe`} src={iframUrl} title={type}/>
      </div>
    )
  }
}